package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.xiaomili.halfsugar.R;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2016/7/19 0019.
 */
public class RecAdapter extends RecyclerView.Adapter<RecAdapter.PicHolder> {

    private Context mContext;
    private List<String> mDatas;


    public RecAdapter(Context mContext, List<String> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }

    @Override
    public PicHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_grid, parent, false);
        return new PicHolder(view);
    }

    @Override
    public void onBindViewHolder(PicHolder holder, int position) {
        if (position==0){
            Picasso.with(mContext).load(mDatas.get(position))
                    .centerInside()
                    .config(Bitmap.Config.RGB_565)
                    .resize(200,200)
                    .into(holder.iv_grid);
        }else{
            Picasso.with(mContext).load(new File(mDatas.get(position)))
                    .centerInside()
                    .config(Bitmap.Config.RGB_565)
                    .resize(200,200)
                    .into(holder.iv_grid);
        }
    }

    @Override
    public int getItemCount() {
        Log.i("tag","size--->>>"+mDatas.size());
        return mDatas==null?0:mDatas.size();
    }

    //    @Override
//    public int getItemViewType(int position) {
//        if (position==0){
//            return IApp.TYPE_CRAMER;
//        }
//        return IApp.TYPE_PIC;
//    }
//
//    @Override
//    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        switch (viewType){
//            case IApp.TYPE_CRAMER:
//                View view = LayoutInflater.from(mContext).inflate(R.layout.item_head, parent, false);
//                return new CramerHolder(view);
//            case IApp.TYPE_PIC:
//                View view1 = LayoutInflater.from(mContext).inflate(R.layout.item_grid,parent,false);
//                return new PicHolder(view1);
//        }
//        return null;
//    }
//
//    @Override
//    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        int itemType = getItemViewType(position);
//        switch (itemType){
//            case IApp.TYPE_CRAMER:
//                CramerHolder cramerHolder = (CramerHolder) holder;
//                Picasso.with(mContext).load(mDatas.get(position))
//                        .config(Bitmap.Config.RGB_565)
//                        .resize(200,200)
//                        .centerInside()
//                        .into(cramerHolder.iv_cramer);
//                break;
//            case  IApp.TYPE_PIC:
//                PicHolder picHolder = (PicHolder) holder;
//                Picasso.with(mContext).load(new File(mDatas.get(position)))
//                        .config(Bitmap.Config.RGB_565)
//                        .resize(200,200)
//                        .centerInside()
//                        .into(picHolder.iv_grid);
//                break;
//        }
//    }
//
//    @Override
//    public int getItemCount() {
//        Log.i("tag","size--->>>"+mDatas.size());
//        return mDatas==null?0:mDatas.size();
//    }
//
//    class CramerHolder extends RecyclerView.ViewHolder{
//
//        private ImageView iv_cramer;
//       public CramerHolder(View itemView) {
//           super(itemView);
//           iv_cramer = (ImageView) itemView.findViewById(R.id.iv_camera);
//       }
//   }
    class PicHolder extends RecyclerView.ViewHolder{
        private ImageView iv_grid;
        public PicHolder(View itemView) {
            super(itemView);
            iv_grid= (ImageView) itemView.findViewById(R.id.iv_grid);
        }
    }
}
